﻿Imports System.Linq

Namespace Configuration.Templating.Context
    Public Class TemplatingContext
        Implements ITemplatingContext

        Public Property Separator As String = "."

        Private Property Keys As IEnumerable(Of String)
        Private _Key As String = Nothing

        Public Sub New(ResourceKeys As IEnumerable(Of String))
            Keys = ResourceKeys
            _Key = String.Join(Separator, Keys.Where(Function(s) Not String.IsNullOrEmpty(s)).ToArray())
        End Sub

        Public Function GetParentContext() As ITemplatingContext Implements ITemplatingContext.GetParentContext
            Dim NewKeys As IEnumerable(Of String) = Keys.Take(Keys.Count - 1)
            If NewKeys.Count = 0 Then
                Return Nothing
            Else
                Return New TemplatingContext(NewKeys)
            End If
        End Function

        Public ReadOnly Property Key As String Implements ITemplatingContext.Key
            Get
                Return _Key
            End Get
        End Property
    End Class
End Namespace